<?php
/**
 * Celebrio global Azure storage table
 *
 * @copyright  Copyright (c) 2012 Celebio Software, s.r.o.
 * @package    Kernel
 */
namespace Celebrio\WindowsAzure\AzureStorage;

use Nette\Object;

use \Microsoft_WindowsAzure_Storage_Table;

use Celebrio\WindowsAzure\AzureStorage\GlobalAzureRetryPolicy;

/**
 * Singleton for Azure Storage BLOB
 *
 * @author Martin Novák
 */
class AzureStorageTable extends Object {
	/**
	 * @var Microsoft_WindowsAzure_Storage_Table
	 */
	private static $instance;

    private function __construct()
    {
    	trigger_error('Construct is not allowed.', E_USER_ERROR);
    }

    public static function connection()
    {
        if (!isset(self::$instance)) {
            self::$instance = new Microsoft_WindowsAzure_Storage_Table(
	            	azure_getconfig("TableStorageEndpoint"),
	            	azure_getconfig("StorageAccountName"),
	            	azure_getconfig("StorageAccountKey"),
	            	false,
	            	new GlobalAzureRetryPolicy());
        }
        return self::$instance;
    }
    
    /**
     * returns true if we are using Windows Azure development storage
     *
     * @return bool
     */
    public static function isDevelopmentStorage(){
    	if(azure_getconfig("StorageAccountName") == "devstoreaccount1") return TRUE;
    	else return FALSE;
    }

    public function __clone()
    {
        trigger_error('Clone is not allowed.', E_USER_ERROR);
    }

    public function __wakeup()
    {
        trigger_error('Unserializing is not allowed.', E_USER_ERROR);
    }
}